package com.woniu.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.Service.DeptService;
import com.woniu.entity.Dept;
import com.woniu.entity.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController

public class DeptController {
    @Autowired
    private DeptService deptService;

    @RequestMapping("findAll")
    public ResultVO findAll(@RequestParam(defaultValue = "1")Integer pageNum,@RequestParam("5")Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Dept> list = deptService.findAll();
        PageInfo<Dept> pi = new PageInfo<>(list);
        return ResultVO.success("查询成功",pi);
    }

    @RequestMapping("add")
    public ResultVO add(Dept dept){
        boolean flag = deptService.addDept(dept);
        return ResultVO.success("添加成功");
    }

    @RequestMapping("del")
    public ResultVO del(Integer dno){
        boolean flag = deptService.delDept(dno);
        return ResultVO.success("删除成功");
    }

    @RequestMapping("update")
    public ResultVO update(Dept dept){
        boolean flag = deptService.upDept(dept);
        return ResultVO.success("修改成功");
    }
}
